package com.petmarket.controller;


import com.alibaba.fastjson.JSON;
import com.petmarket.common.AccountManger;
import com.petmarket.common.Result;
import com.petmarket.common.TransactionManager;
import com.petmarket.entity.AccountKeyPair;
import com.petmarket.entity.LoginDetail;
import com.petmarket.uitls.SpringUtils;
import lombok.extern.slf4j.Slf4j;
import org.fisco.bcos.sdk.jni.common.JniException;
import org.fisco.bcos.sdk.v3.BcosSDK;
import org.fisco.bcos.sdk.v3.codec.ContractCodecException;
import org.fisco.bcos.sdk.v3.crypto.keypair.CryptoKeyPair;
import org.fisco.bcos.sdk.v3.transaction.model.exception.ContractException;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.KeyPair;

@RestController
@RequestMapping("/test")
@Slf4j
public class TestController {


    @PostMapping("/fun1")
    public Result test() {

        String accountKey = AccountManger.createAccountKey();

        return Result.ok(accountKey);

    }

    @PostMapping("/fun2")
    public Result test2(@RequestBody AccountKeyPair accountKeyPair) {

        CryptoKeyPair cryptoKeyPair = AccountManger.loadAccount(accountKeyPair.getHexPrivateKey());

        return Result.ok(cryptoKeyPair.getHexPrivateKey());

    }

    @PostMapping("/fun3")
    public Result tes3() throws ContractException, JniException, ContractCodecException {

        //String accountKey = AccountManger.createAccountKey();

        BcosSDK sdk = SpringUtils.getBean("bcosSDK");
        TransactionManager.sendTransaction("User",sdk,"12");

        return Result.ok();

    }


}
